package cn.com.surker.lab.service.impl;

import cn.com.surker.enums.StateEnum;
import cn.com.surker.lab.entity.LabExpend;
import cn.com.surker.lab.service.ErpLabExpendService;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luotao
 * @date 2024/11/5
 */
@Service
public class ErpLabExpendImpl extends LabExpendBaseImpl implements ErpLabExpendService {


	@Override
	public void delByInvBatch(Long invoiceId, Long batchId, String remark) {
		if (invoiceId == null) {
			return;
		}
		UpdateWrapper<LabExpend> uw = new UpdateWrapper<>();
		uw.eq("invoice_id", invoiceId);
		if (batchId != null) {
			uw.eq("batch_id", batchId);
		}
		if (StringUtils.isNotBlank(remark)) {
			uw.set("remark", remark);
		}
		uw.set("status", StateEnum.DISABLED.getCode());
		//int delete = labExpendDao.delete(uw);
		labExpendDao.update(new LabExpend(), uw);
	}

	@Override
	public List<LabExpend> findSackStorageList(Long invoiceId, String startTime, String endTime) {
		QueryWrapper<LabExpend> qw = new QueryWrapper<>();
		qw.eq("status", StateEnum.ENABLED.getCode());
		qw.isNull("storage_id");
		if (StringUtils.isNotBlank(startTime)) {
			qw.ge("use_time", startTime);
		}
		if (StringUtils.isNotBlank(endTime)) {
			qw.lt("use_time", endTime);
		}
		if (invoiceId != null) {
			qw.eq("invoice_id", invoiceId);
		}
		List<LabExpend> expendList = labExpendDao.selectList(qw);
		return expendList;
	}
}
